package com.yourname.myapplication.viewmodel


import androidx.lifecycle.ViewModel
import androidx.lifecycle.viewModelScope
import com.yourname.myapplication.database.AppDatabase
import com.yourname.myapplication.model.StudyRecord
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.launch

class StudyRecordViewModel(private val appDatabase: AppDatabase) : ViewModel() {

    fun insertRecord(record: StudyRecord) {
        viewModelScope.launch {
            appDatabase.studyRecordDao().insertRecord(record)
        }
    }

    fun getRecordsByUserId(userId: Int): Flow<List<StudyRecord>> {
        return appDatabase.studyRecordDao().getRecordsByUserId(userId)
    }
}